package org.dreamwork.jasmine2.parser;

/**
 * Created by IntelliJ IDEA.
* User: seth
* Date: 2009-1-22
* Time: 15:52:44
* To change this template use File | Settings | File Templates.
*/
public class TaglibDirective extends JspDirective {
    String uri, prefix, name;

    public TaglibDirective (String content) {
        super (content);
        type = TYPE_TAGLIB;
    }

    public String getURI () {
        return uri;
    }

    public String getPrefix () {
        return prefix;
    }

    public String getName () {
        return name;
    }

    public void parse () {
        char[] buff = content.toCharArray ();
        int pos = content.indexOf ("uri");

        int start = skipUntil ("\"", buff, pos);
        int end = skipUntil ("\"", buff, start + 1);
        uri = new String (buff, start + 1, end - start - 1);

        pos = content.indexOf ("prefix");
        start = skipUntil ("\"", buff, pos);
        end = skipUntil ("\"", buff, start + 1);
        prefix = new String (buff, start + 1, end - start - 1);

        pos = content.indexOf ("name");
        if (pos >= 0) {
            start = skipUntil ("\"", buff, pos);
            end = skipUntil ("\"", buff, start + 1);
            name = new String (buff, start + 1, end - start - 1);
        }
    }

    public String toString () {
        String s = "<%@ taglib uri = \"" + uri + "\" prefix = \"" + prefix + "\"";
        if (name != null && name.trim ().length () > 0)
            s += " name=\"" + name + "\"";
        s += "%>";
        return s;
    }
}
